﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using HiStaff.Util;

namespace HiStaff.iSystem
{
    public class Service
    {
        #region private static variables
        private static ServiceCommon.CommonClient commonClient;
        private static ServiceSystem.SystemClient systemClient;
        private static ServiceProfile.ProfileClient profileClient;
        private static ServiceInsurance.InsuranceClient insuranceClient;
        private static ServiceTime.TimeClient timeClient;
        private static ServicePayroll.PayrollClient payrollClient;
        #endregion

        #region public static variables
        public static ServiceCommon.CommonClient CommonClient
        {
            get
            {
                if (commonClient == null)
                    commonClient = new ServiceCommon.CommonClient();
                if (commonClient.State == System.ServiceModel.CommunicationState.Closed ||
                    commonClient.State == System.ServiceModel.CommunicationState.Created)
                    commonClient.Open();
                return commonClient;
            }
        }
        public static ServiceSystem.SystemClient SystemClient
        {
            get
            {
                if (systemClient == null)
                    systemClient = new ServiceSystem.SystemClient();
                if (systemClient.State == System.ServiceModel.CommunicationState.Closed ||
                    systemClient.State == System.ServiceModel.CommunicationState.Created)
                    systemClient.Open();
                return systemClient;
            }
        }
        public static ServiceProfile.ProfileClient ProfileClient
        {
            get
            {
                if (profileClient == null)
                    profileClient = new ServiceProfile.ProfileClient();
                if (profileClient.State == System.ServiceModel.CommunicationState.Closed ||
                    profileClient.State == System.ServiceModel.CommunicationState.Created)
                    profileClient.Open();
                return profileClient;
            }
        }
        public static ServiceInsurance.InsuranceClient InsuranceClient
        {
            get
            {
                if (insuranceClient == null)
                    insuranceClient = new ServiceInsurance.InsuranceClient();
                if (insuranceClient.State == System.ServiceModel.CommunicationState.Closed ||
                    insuranceClient.State == System.ServiceModel.CommunicationState.Created)
                    insuranceClient.Open();
                return insuranceClient;
            }
        }
        public static ServiceTime.TimeClient TimeClient
        {
            get
            {
                if (timeClient == null)
                    timeClient = new ServiceTime.TimeClient();
                if (timeClient.State == System.ServiceModel.CommunicationState.Closed ||
                    timeClient.State == System.ServiceModel.CommunicationState.Created)
                    timeClient.Open();
                return timeClient;
            }
        }
        public static ServicePayroll.PayrollClient PayrollClient
        {
            get
            {
                if (payrollClient == null)
                    payrollClient = new ServicePayroll.PayrollClient();
                if (payrollClient.State == System.ServiceModel.CommunicationState.Closed ||
                    payrollClient.State == System.ServiceModel.CommunicationState.Created)
                    payrollClient.Open();
                return payrollClient;
            }
        }
        #endregion

        #region public static method
        public static DataTable ExcuteStoreToDataTable(string packname, string procname, object parameter)
        {
            return CommonClient.ExcuteStoreToDataTable(packname, procname, ConvertHelper.ObjectToDataTable(parameter));
        }
        public static DataTable ExcuteStoreToDataTable(string packname, string procname)
        {
            return ExcuteStoreToDataTable(packname, procname, new DataTable("T"));
        }
        public static DataTable ExcuteStoreToDataTable(string procname, object parameter)
        {
            return ExcuteStoreToDataTable(string.Empty, procname, parameter);
        }
        public static DataTable ExcuteStoreToDataTable(string procname)
        {
            return ExcuteStoreToDataTable(string.Empty, procname, new DataTable("T"));
        }

        public static DataSet ExcuteStoreToDataSet(string packname, string procname, object parameter)
        {
            return CommonClient.ExcuteStoreToDataSet(packname, procname, ConvertHelper.ObjectToDataTable(parameter));
        }
        public static DataSet ExcuteStoreToDataSet(string packname, string procname)
        {
            return ExcuteStoreToDataSet(packname, procname, new DataTable("T"));
        }
        public static DataSet ExcuteStoreToDataSet(string procname, object parameter)
        {
            return ExcuteStoreToDataSet(string.Empty, procname, parameter);
        }
        public static DataSet ExcuteStoreToDataSet(string procname)
        {
            return ExcuteStoreToDataSet(string.Empty, procname, new DataTable("T"));
        }

        public static bool ExcuteStoreNonQuery(string packname, string procname, object parameter)
        {
            return CommonClient.ExcuteStoreNonQuery(packname, procname, ConvertHelper.ObjectToDataTable(parameter));
        }
        public static bool ExcuteStoreNonQuery(string packname, string procname)
        {
            return ExcuteStoreNonQuery(packname, procname, new DataTable("T"));
        }
        public static bool ExcuteStoreNonQuery(string procname, object parameter)
        {
            return ExcuteStoreNonQuery(string.Empty, procname, parameter);
        }
        public static bool ExcuteStoreNonQuery(string procname)
        {
            return ExcuteStoreNonQuery(string.Empty, procname, new DataTable("T"));
        }

        #endregion

    }
}
